﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;

namespace Web.Filters
{
    public class MyActionFilter : IActionFilter
    {

        /// <summary>
        /// 耗时监控
        /// </summary>
        /// <param name="context"></param>
        /// 
        Stopwatch stopwatch = new Stopwatch();

        public  void OnActionExecuted(ActionExecutedContext context)
        {
            //throw new NotImplementedException();
            stopwatch.Stop(); 
            Console.WriteLine($"{context.RouteData.Values["Controller"] +"-"+ context.RouteData.Values["Action"]}，用时{stopwatch.ElapsedMilliseconds}毫秒" );
        }

        public  void OnActionExecuting(ActionExecutingContext context)
        {
            //throw new NotImplementedException();

            stopwatch.Start();
        }
    }
}
